import 'package:flutter/material.dart';

import '../../common/common.dart';
import '../widget/item/my_item.dart';
import '../widget/my_scaffold.dart';

class MyAppLanguagePage extends StatefulWidget {
  const MyAppLanguagePage({super.key});

  @override
  State<MyAppLanguagePage> createState() => _MyAppLanguagePageState();
}

class _MyAppLanguagePageState extends State<MyAppLanguagePage> {
  @override
  Widget build(BuildContext context) {
    return MyScaffold(
      title: "显示语言",
      bottomSafeArea: false,
      body: ListView.builder(
        padding: EdgeInsets.zero,
        itemCount: I18n.languages.length,
        itemBuilder: (BuildContext context, int index) {
          AppLanguage appLanguage = I18n.languages[index];
          return MyItem(
            title: index == 0 ? appLanguage.name.i18n : appLanguage.name,
            type: MyItemType.options,
            isOn: I18n.languageCode == appLanguage.code,
            i18n: false,
            onTap: () {
              setState(() {
                I18n.setLanguage(appLanguage);
              });
            },
          );
        },
      ),
    );
  }
}
